<?php
class Admin_Model_Product extends Zend_Db_Table_Abstract
{
	public function getidproduct($product)
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchRow($db->select()->from('product','id_product')->where('name_product = ?',$product));
		return $data;
	}
	public function getidcatelog($catelog)
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchRow($db->select()->from('catelory',array('id_catelog','folder_category'))->where('name_catelog = ?',$catelog));
		return $data;
	}
	public function getallnamecatelog()
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchAll($db->select()->from('catelory','name_catelog'));
		return $data;
	}
	public function getallproduct()
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchAll($db->select()->from('product','name_product'));
		return $data;
	}
	public function add($id,$name,$catelog,$updatedate,$count,$price,$descrip,$id_user,$folder)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('id_product'=>$id,'name_product'=>$name,'id_catelog'=>$catelog,'dateproduct'=>$updatedate,'count'=>$count,'price'=>$price,'descript'=>$descrip,'id_user'=>$id_user,'folder_product'=>$folder);
		$add = $db->insert('product',$data);
		return $add;
	}
	public function edit($id,$name,$catelog,$updatedate,$count,$price,$descrip,$id_user)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('name_product'=>$name,'id_catelog'=>$catelog,'dateproduct'=>$updatedate,'count'=>$count,'price'=>$price,'descript'=>$descrip,'id_user'=>$id_user);
		$where = $db->quoteInto('id_product =?',$id);
		$add = $db->update('product',$data,$where);
		return $add;
	}
	public function search($content)
	{
		$db = Zend_Registry::get('connectDB');
		$where = $db->quoteInto('name_product LIKE ? OR id_product LIKE ? OR dateproduct LIKE ?','%'.$content.'%');
		$data = $db->fetchAll($db->select()->from('product')->joinInner('users','users.id_user=product.id_user')->where($where));
		return $data;
	}
	public function getAll()
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchAll($db->select()->from('product')->joinInner('users','users.id_user=product.id_user'));
		return $data;
	}
	public function getId($id)
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchRow($db->select()->from('product')->where('id_product=?',$id));
		return $data;
	}
	public function getproduct($id_catelog)
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchAll($db->select()->from('product','name_product')->where('id_catelog = ?',$id_catelog));
		return $data;
	}
	public function addimg($name_url,$filename,$size,$id_product)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('name_urlimg'=>$name_url,'filename'=>$filename,'size'=>$size,'id_product'=>$id_product);
		$insert = $db->insert('urlimage',$data);
		return $insert;
	}
	public function addvideoytb($name_video,$date,$path,$id_product,$user,$id_server)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('name_video'=>$name_video,'updatedate'=>$date,'name_urlvideo'=>$path,'id_product'=>$id_product,'id_user'=>$user,'id_serverup'=>$id_server);
		$insert = $db->insert('urlvideo',$data);
		return $insert;
	}
	public function addvideo($name_video,$date,$path,$size,$id_product,$user,$server)
	{
		$db = Zend_Registry::get('connectDB');
		$data = array('name_video'=>$name_video,'updatedate'=>$date,'name_urlvideo'=>$path,'size_video'=>$size,'id_product'=>$id_product,'id_user'=>$user,'id_serverup'=>$server);
		$insert = $db->insert('urlvideo',$data);
		return $insert;
	}
	public function delete($id)
	{
		$db = Zend_Registry::get('connectDB');
		$where = $db->quoteInto('id_product =?',$id);
		$delete = $db->delete('product',$where);
		return $delete;
	}
	public function getvideo($id_product)
	{
		$db = Zend_Registry::get('connectDB');
		$data = $db->fetchAll($db->select()->from('urlvideo','name_video')->where('id_product =?',$id_product));
		return $data;
	}
}